﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using YJKArchMethodLibrary.Utils;
using ModelChecking.ModelValidation.Utils;
using SectionSignAndFilled.StairsClearHeightDimension;
using StairsModuleAndEdit.StairsModel.CommonUnit;

namespace ModelChecking.ModelValidation.StairsRamp
{
	internal class StairsData
	{
		public static List<double> GetRunWidth(Document document, ElementId stairsId)
		{
			Stairs stairs = document.GetElement(stairsId) as Stairs;
			if (stairs == null)
			{
				return null;
			}
			List<double> list = new List<double>();
			ICollection<ElementId> stairsRuns = stairs.GetStairsRuns();
			foreach (ElementId elementId in stairsRuns)
			{
				StairsRun stairsRun = document.GetElement(elementId) as StairsRun;
				CurveLoop footprintBoundary = stairsRun.GetFootprintBoundary();
				Curve curve = stairsRun.GetStairsPath().First<Curve>();
				double num = 0.0;
				if (curve.GetType() == typeof(Line))
				{
					Line line = curve as Line;
					IEnumerator<Curve> enumerator2 = footprintBoundary.GetEnumerator();
					{
						while (enumerator2.MoveNext())
						{
							Curve curve2 = enumerator2.Current;
							Line line2 = curve2 as Line;
							if (!(null == line2) && ModelChecking.ModelValidation.Utils.Geometry.IsVertical(line.Direction, line2.Direction))
							{
								num = YJKArchMethodLibrary.Utils.Common.FeetToMM(line2.Length);
								break;
							}
						}
						goto IL_1A0;
					}
					goto IL_EC;
				}
				goto IL_EC;
				IL_1A0:
				list.Add(num);
				continue;
				IL_EC:
				Arc arc = curve as Arc;
				foreach (Curve curve3 in footprintBoundary)
				{
					Line line3 = curve3 as Line;
					if (!(null == line3) && YJKArchMethodLibrary.Utils.Geometry.Is_Points_Collinear(line3.GetEndPoint(0), line3.GetEndPoint(1), arc.Center, 1E-09))
					{
						num = line3.Length;
						break;
					}
				}
				double num2 = YJKArchMethodLibrary.Utils.Common.FeetToMM(num);
				int @int = YJKArchMethodLibrary.Utils.Common.GetInt(num2);
				if (1E-05 >= Math.Abs(num2 + 1E-07 - (double)@int))
				{
					num2 = (double)@int;
				}
				num = num2;
				goto IL_1A0;
			}
			return list;
		}

		public static double GetTreadHeight(Document document, ElementId stairsId)
		{
			Stairs stairs = document.GetElement(stairsId) as Stairs;
			if (stairs == null)
			{
				return 0.0;
			}
			return YJKArchMethodLibrary.Utils.Common.FeetToMM(stairs.ActualRiserHeight);
		}

		public static double GetTreadDepth(Document document, ElementId stairsId)
		{
			Stairs stairs = document.GetElement(stairsId) as Stairs;
			if (stairs == null)
			{
				return 0.0;
			}
			return YJKArchMethodLibrary.Utils.Common.FeetToMM(stairs.ActualTreadDepth);
		}

		public static string GetStairsHeight(StairsClearHeightMgr stairsCHM, ElementId stairsId)
		{
			string result = "";
			stairsCHM.CheckStairsClearHeight(StairsClearHeightMgr.CheckType.CT_SRUN, stairsId, out result);
			return result;
		}

		public static string GetLandHeight(StairsClearHeightMgr stairsCHM, ElementId stairsId)
		{
			string result = "";
			stairsCHM.CheckStairsClearHeight(StairsClearHeightMgr.CheckType.CT_SLAND, stairsId, out result);
			return result;
		}

		public static List<double> GetLandWidth(Document document, ElementId stairsId)
		{
			Stairs stairs = document.GetElement(stairsId) as Stairs;
			if (stairs == null)
			{
				return null;
			}
			return ElementXDataManager.ReadStairsLandXData(stairs, "LandWidth");
		}

		public static double GetStairsSelfHeight(Document document, ElementId stairsId)
		{
			Stairs stairs = document.GetElement(stairsId) as Stairs;
			if (stairs == null)
			{
				return 0.0;
			}
			return YJKArchMethodLibrary.Utils.Common.FeetToMM(stairs.Height);
		}
	}
}
